package org.box.metadata.shell.console;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.box.metadata.cli.MetaCommandLineParser.ParserType;
import org.box.metadata.shell.AbstractShell;
import org.box.metadata.shell.Shell;

/**
 * Provides Shell's implementation for console and provides two simple commands:
 * 
 * <li> {@link HelpCommandHandler} - Prints a list of available applications and commands
 * <li> {@link ExitCommandHandler} - Performs exit from the shell
 *
 * @see Shell
 * 
 * @author <a href="mailto:alexander.box@gmail.com">Alexander Korobka</a>
 * 
 */
public class ConsoleShell extends AbstractShell {

	public ConsoleShell(Class<?> cfgClass) {
		super(cfgClass, ConsoleDefaultConfiguration.class);
	}

	public ConsoleShell(ParserType parserType, Class<?> cfgClass) {
		super(parserType, cfgClass, ConsoleDefaultConfiguration.class);
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.box.metadata.shell.AbstractShell#getUserInput()
	 */
	@Override
	protected String getUserInput() {
		System.out.print(">");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}


	/*
	 * (non-Javadoc)
	 * @see org.box.metadata.shell.Shell#displayMessage(org.box.metadata.shell.message.ShellMessage)
	 */
	public void displayMessage(String msg) {
		System.out.println(msg);
	}

}
